<?php
//Name: Admin.php
//Purpose: This script is for administrators to view all users 
//CreateDate: 10/01/12
//check if user is admin, create session var to declare if is admin
session_name('login');
session_start();
if($_SESSION['isAdmin'] == false)
{
	header("location: /home.php");
	exit;
}

include 'util.php';

$dbConnection = getMySqlConnection();

$query ="SELECT o.order_id, p.username, o.date 
FROM person p, orders o
WHERE p.person_id = o.person_id
ORDER BY p.username, o.date;";

$result = $dbConnection->query($query);

$numberOfUsers = $result->num_rows;

//display all all users info

//dispaly total users

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
	<head>
		<script src="javascript/tcaparrel.js" type="text/javascript"></script>
		<link rel="StyleSheet" href="css/tcaparrel.css" type="text/css">
		<link rel="StyleSheet" href="css/header.css" type="text/css">
	</head>

	<body class="productPage">
	<div class="contentWrapper">
		<div class="header">
		<?php 
		session_name('login');
		session_start();
		if(isset($_SESSION['username']))
		{
			include('loggedInUserHeader.php');
		}
		else
		{
			include ('loginformheader.php');
		}
		?>
		</div>
		
		<div class="menubarContentWrapper">
			<div class="menubar">
				<div class="menuItem" onclick="sweatshirts_click()"><label style="cursor: inherit">SweatShirts</label></div>
				<div class="menuItem" onclick="hats_click()"><label style="cursor: inherit">Hats</label></div>
				<div class="menuItem" onclick="tshirts_click()"><label style="cursor: inherit">T-Shirts</label></div>
				<div class="menuItem" onclick="pants_click()"><label style="cursor: inherit">Pants</label></div>
			</div>
		</div>
		
		<div class="adminContainer">
			<h1>View All Orders</h1>
			<div class="allUsers">
				Total Number of Past Orders: <?php echo $numberOfUsers; ?>
			</div>
			
				<table class="allUsers">
					<tr>
						<th>Order Number</th>
						<th>Customer</th>
						<th>Date</th>
					</tr>
					
				<?php 
				
					while($userResult = $result->fetch_assoc())
					{
						$orderId= $userResult['order_id'];
						$username = $userResult['username'];
						$date = $userResult['date'];
						echo "
					<tr>
						<td class='allUsers'>$orderId</td>
						<td class='allUsers'>$username</td>
						<td class='allUsers'>$date</td>
					</tr>
							";
					}
				?>
				</table>
		</div>
		
		<div class="footer"></div>
		</div>
	</body>

</html>